import { forwardRef, MiddlewareConsumer, Module, NestModule } from '@nestjs/common';
import { PassportModule } from '@nestjs/passport';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserActivityLoggerMiddleware } from '../../middlewares/user-activity-logger.middleware';
import { OrganizationModule } from '../organization/organization.module';
import { UserModule } from '../user/user.module';
import { AreaAdminController } from './controllers/admin/area.admin.controller';
import { AreaAnonymousController } from './controllers/anonymous/area.anonymous.controller';
import { AreaGuardController } from './controllers/guard/area.guard.controller';
import { AreaRoleController } from './controllers/role/area.role.controller';
import { AreaEntity } from './entities/area.entity';
import { AreaService } from './services/area.service';

@Module({
  imports: [PassportModule.register({ defaultStrategy: 'bearer' }), TypeOrmModule.forFeature([AreaEntity]), OrganizationModule, forwardRef(() => UserModule)],
  controllers: [AreaAdminController, AreaRoleController, AreaGuardController, AreaAnonymousController],
  providers: [AreaService],
  exports: [AreaService]
})
export class AreaModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(UserActivityLoggerMiddleware).forRoutes(AreaAdminController, AreaRoleController, AreaGuardController, AreaAnonymousController);
  }
}
